<?php

namespace backend\models\user;

use Yii;

/**
 * This is the model class for table "{{%edu_like}}".
 *
 * @property integer $like_id
 * @property integer $user_id
 * @property integer $teacher_id
 * @property integer $like_addtime
 */
class Like extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%like}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'teacher_id', 'like_addtime'], 'required'],
            [['user_id', 'teacher_id', 'like_addtime'], 'integer']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'like_id' => 'Like ID',
            'user_id' => 'User ID',
            'teacher_id' => 'Teacher ID',
            'like_addtime' => 'Like Addtime',
        ];
    }
	//查询该教师的喜欢数
	public function LikeCount($teacher_id)
    {
		return $this -> find()
					 -> where(['=','teacher_id',$teacher_id])
					 -> count();
    }
	//查询是否存在
	public function Like($user_id,$teacher_id)
    {
		return $this -> find()
					 -> where(['and',['=','user_id',$user_id],['=','teacher_id',$teacher_id]])
					 -> asArray()
					 -> one();
    }
}
